package com.medvalley.tcm.dao;

import com.medvalley.tcm.domain.Music2Category;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface Music2CatetoryDao extends CrudRepository<Music2Category, Integer> {

    List<Music2Category> findAllByCategoryId(int categoryId);

    //    @Query(nativeQuery = true, value = " SELECT   * FROM   t_music_2_category t1 WHERE t1.id >=  ((SELECT MAX(id)  FROM `t_music_2_category` where category_id = :categoryId) -  (SELECT  MIN(id)  FROM  t_music_2_category where  category_id = :categoryId )) * RAND() +  (SELECT MIN(id) FROM  t_music_2_category where  category_id = :categoryId) and  category_id = :categoryId  LIMIT :num")
    @Query(nativeQuery = true, value = " SELECT   * FROM   t_music_2_category t1 WHERE t1.category_id= :categoryId order by rand() LIMIT :num")
    List<Music2Category> findByRand(@Param(value = "num") int num, @Param(value = "categoryId") int categoryId);
}
